package event;

import giaodien.FormChinh;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class MyWindownEvent implements WindowListener {
	FormChinh form;
	public MyWindownEvent(FormChinh form) {
		this.form=form;
	}

	@Override
	public void windowActivated(WindowEvent arg0) {
		form.hanghoa.ketnoi.ktrahost("jdbc:oracle:thin:@//localhost:1521/orcl","system", "123456");
		form.hanghoa.ketnoi.excuteQuery("select * from hanghoa",true);
	}

	@Override
	public void windowClosed(WindowEvent arg0) {
		
	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		if(arg0.getSource()==form){
			int n=JOptionPane.showConfirmDialog(form, "Bạn có muốn thoát không", "Cảnh Báo", JOptionPane.YES_NO_OPTION);
			if(n==JOptionPane.YES_OPTION){
				System.exit(0);
			}
			if(n==JOptionPane.NO_OPTION){
				form.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			}
		}
		if(arg0.getSource()==form.hanghoa){
			int n=JOptionPane.showConfirmDialog(form.hanghoa, "Bạn có muốn thoát không", "Cảnh Báo", JOptionPane.YES_NO_OPTION);
			if(n==JOptionPane.YES_OPTION){
				System.exit(0);
			}
			if(n==JOptionPane.NO_OPTION){
				form.hanghoa.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			}
		}
	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {
		
	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {
		
	}

	@Override
	public void windowIconified(WindowEvent arg0) {
		
	}

	@Override
	public void windowOpened(WindowEvent arg0) {
		form.hanghoa.ketnoi.ktrahost("jdbc:oracle:thin:@//localhost:1521/orcl","system", "123456");
		form.hanghoa.ketnoi.excuteQuery("select * from hanghoa",true);
	}

}
